﻿Imports System.Data.SqlClient
Imports System.Xml
Imports System.Data.OleDb

Public Class Feed
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Response.Clear()
        Response.ContentType = "application/rss+xml"
        Dim objX As New XmlTextWriter(Response.OutputStream, Encoding.UTF8)
        objX.WriteStartDocument()
        objX.WriteStartElement("rss")
        objX.WriteAttributeString("version", "2.0")
        objX.WriteStartElement("channel")

        'define the oledb database connection this is not a sql connection
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("roboticsConnectionString").ConnectionString)
        ' my query string
        Dim SqlString As String = ("SELECT * FROM mastTable1")

        ' for running the query over the db
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Connection.Open()
        'executing the ole db reader
        Dim dr As OleDbDataReader = cmd.ExecuteReader
        
        objX.WriteElementString("iRobotics", "RSS News Feed")
        objX.WriteElementString("link", "cvcvv")
        objX.WriteElementString("description", "iRobotics. A unique website for lovers of Robots.Let the battle commence!!!")
        objX.WriteElementString("language", "en-uk")
        objX.WriteElementString("ttl", "1")
        objX.WriteElementString("image", "dddf")
        objX.WriteElementString("lastBuildDate", String.Format("{0:R}", DateTime.Now))

        Do While dr.Read()


            objX.WriteStartElement("item")
            objX.WriteElementString("title", dr("Robot_Name").ToString())
            objX.WriteElementString("description", "One of our Famous Robots has been added for battle")
            objX.WriteElementString("pubDate", String.Format("{0:R}", dr("DateTimeAdded")))
            objX.WriteEndElement()


           

        Loop

        objX.WriteEndElement()
        objX.WriteEndElement()
        objX.WriteEndDocument()
        objX.Flush()
        objX.Close()
        cmd.Connection.Close()
        oleDbConn.Close()
        Response.End()
    End Sub


End Class